
package com.kugou.game.sdk.ui.dialog;

import android.app.Activity;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.kugou.game.sdk.utils.Rx;

public class MobileRechargeConfirmDialog extends BaseSDKDialog {

    protected Activity activity;

    private Button btnOk, btnCancel;

    private TextView tvMessage1, title, tvMessage2, tvMessage3;

    private ImageView ivClose;

    private View line, diver;

    public MobileRechargeConfirmDialog(Activity activity, int theme) {
        super(activity, theme);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        this.activity = activity;
        initView();
    }

    public MobileRechargeConfirmDialog(Activity activity) {
        this(activity, 0);
    }

    private void initView() {
        int layoutId = Rx.layout.kg_mobile_confirm_dialog;
        setContentView(layoutId);
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        btnOk = (Button) findViewById(Rx.id.kg_common_dialog_btn_ok);
        if (btnOk == null) {
            throw new RuntimeException(
                    "Your content must have a ImageButton whose id attribute is "
                            + "'R.id.kg_common_dialog_btn_ok'");
        }
        btnCancel = (Button) findViewById(Rx.id.kg_common_dialog_btn_cancel);
        if (btnCancel == null) {
            throw new RuntimeException(
                    "Your content must have a ImageButton whose id attribute is "
                            + "'R.id.kg_common_dialog_btn_cancel'");
        }
        ivClose = (ImageView) findViewById(Rx.id.kg_iv_close);
        if (ivClose == null) {
            throw new RuntimeException("Your content must have a ImageView whose id attribute is "
                    + "'R.id.kg_iv_close'");
        }
        ivClose.setOnClickListener(mCloseClickListener);
        btnCancel.setOnClickListener(mCancelClickListener);
        tvMessage1 = (TextView) findViewById(Rx.id.kg_dialog_message_tv1);
        tvMessage2 = (TextView) findViewById(Rx.id.kg_dialog_message_tv2);
        tvMessage3 = (TextView) findViewById(Rx.id.kg_dialog_message_tv3);
        title = (TextView) findViewById(Rx.id.kg_tv_dialog_title);
        line = findViewById(Rx.id.kg_dialog_line);
        diver = findViewById(Rx.id.kg_dialog_btn_diver);
        setOKBtnText("确定");
        setCancelText("取消");
    }

    private View.OnClickListener mCloseClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    private View.OnClickListener mCancelClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    /**
     * 设置关闭按钮的可见性
     * 
     * @param visibility
     */
    public void setCloseVisibility(int visibility) {
        ivClose.setVisibility(visibility);
    }

    public void setOnCloseClickListener(View.OnClickListener listener) {
        ivClose.setOnClickListener(listener);
    }

    public void setOKClickListener(View.OnClickListener listener) {
        btnOk.setOnClickListener(listener);
    }

    public void setCancelClickListener(View.OnClickListener listener) {
        btnCancel.setOnClickListener(listener);
    }

    /**
     * 设置对话框标题
     */
    public void setDialogTitle(String str) {
        title.setText(str);
    }

    /**
     * 设置对话框显示内容
     * 
     * @param kindNames 充值类型集合
     * @param type 充值类型，从1开始
     * @param rechargeValue 充值金额
     * @param youxibi 获得的游戏币或者游币
     */
    public void setRechargeInfo(String kindName, int rechargeValue, String youxibi) {

        tvMessage1.setText(Html.fromHtml("<font color=#ff666666>充值卡类型：</font>"
                + "<font color=#fc5f28>" + kindName + "</font>"));
        tvMessage2.setText(Html.fromHtml("<font color=#ff666666>充值金额：</font>"
                + "<font color=#fc5f28>" + rechargeValue + "元</font>"));
        if (youxibi == null) {
            tvMessage3.setVisibility(View.GONE);
        } else {
            tvMessage3.setText(Html.fromHtml("<font color=#ff666666>您将获得：</font>"
                    + "<font color=#fc5f28>" + youxibi + "</font>"));
        }
    }
}
